Well, even though it’s a bit late in the game, let’s review side effects. In the AROAPL language, all variables are immutable, which means they cannot be reassigned.
11.1. Usage
Add a file named variables.roplsvd as
AROAPL State Variable Definition File
to the working directory where you’re running the
program.
VA: υ[? 5] ← 2 5 ρ 0 8 9 36 2 9 63 8 7 5;
VB: κ[?] ← "STRING DATA";
Here, you can list all your variables. But you must declare their types and initial values. Also, you can only define this file once. It is shared among all programs including referenced modules. Therefore, please list all mutable variables here.
After the definition, nilad functions for referencing state variables and system output for manipulating state variables are automatically reserved internally. This serves a role similar to what are known as getters and setters in object-oriented programming. At the same time, the fact that values can only be accessed via the nilad function means that state variables cannot be deleted. Therefore, they can be safely protected.
⎕ ← ⎕VB;
⎕VB ← "UPDATED STRING DATA";
⎕ ← ⎕VB;
STRING DATA
UPDATED STRING DATA
In chapter 5, you have already learned examples where a value does not necessarily return the same result every time it is read. In chapter 7, you learned that system output plays a role in causing side effects in the host system. In chapter 9, you learned that nilad functions (including anonymous functions) and system output cannot be user-defined. The reasons for this specification have already been discussed in each chapter. However, there is another reason, it was precisely to ensure exclusive access to the reference and control of state variables.
11.2. Why
I believe you are already convinced of the merits of this specification. However, you are probably wondering: Why is this specification being explained so late in the course? This was done quite intentionally. I was very concerned that, without understanding the philosophy of AROAPL, state variables would be used indiscriminately, just as they are in conventional languages. When we discuss this specification, it will be time for you to understand the limitations of side effects and the proper uses of mutable variables.